using UnityEditor;
using UnityEngine;

public static class GraphicsSettingsTool
{
    [MenuItem("[FutureCore]/ProjectSettings/添加常驻着色器", false, 0)]
    public static void AddAlwaysIncludedShader()
    {
        string[] shaders = new string[]
        {
            ///引擎
            //Unity
            "Legacy Shaders/Diffuse",
            "Hidden/CubeBlur",
            "Hidden/CubeCopy",
            "Hidden/CubeBlend",
            "Hidden/VideoDecode",
            "Hidden/VideoDecodeAndroid",
            "Sprites/Default",
            "UI/Default",
            "UI/DefaultETC1",

            ///插件
            //Spine
            "Spine/Skeleton Fill",
            "Spine/SkeletonGraphic Tint Black (Premultiply Alpha)",
            "Spine/SkeletonGraphic (Premultiply Alpha)",
            "Spine/Skeleton Tint Black",
            "Spine/Skeleton",
            "Spine/Skeleton Lit",
            "Hidden/Spine/Bones",
            "Spine/Special/HiddenPass",

            ///框架
            //Effect
            "[FC Effect]/GrabPassBlur",
            "[FC Effect]/HSVRange",
            "[FC Effect]/SimpleGrabPassBlur",
            "[FC Effect]/MoveLightImage",
            //UI
            "[FC UI]/AlphaGradual",
            "[FC UI]/AtlasGrayScale",
            "[FC UI]/CircleGuide",
            "[FC UI]/RectGuide",
            "[FC UI]/Reflection",
            "[FC UI]/SingleGrayScale",
            "[FC UI]/Wave1",
            "[FC UI]/Wave2",
            "[FC UI]/Wave3",
        };

        SerializedObject graphicsSettings = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/GraphicsSettings.asset")[0]);
        SerializedProperty it = graphicsSettings.GetIterator();
        SerializedProperty dataPoint;

        while (it.NextVisible(true))
        {
            if (it.name == "m_AlwaysIncludedShaders")
            {
                it.ClearArray();

                for (int i = 0; i < shaders.Length; i++)
                {
                    it.InsertArrayElementAtIndex(i);
                    dataPoint = it.GetArrayElementAtIndex(i);
                    dataPoint.objectReferenceValue = Shader.Find(shaders[i]);
                }
                graphicsSettings.ApplyModifiedProperties();
            }
        }
    }
}